<template>
	<view>
		 <view class="input-container">
		    <input class="input-field" type="text" placeholder="请输入手机号"  v-model="form.account" />
		  </view>
		  <view class="input-container">
		     <input class="input-field"  type="password" placeholder="请输入密码"  v-model="form.password" />
		   </view>
		   
		     <view class="button"><button @click="onsubmit">登录</button></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{
					account:'',
					password:'',
				}
				
			}
		},
		onLoad() {
		    // 页面加载时获取地址栏参数
		    // console.log('地址栏参数:', this.$Route.query);
		  },
		
		methods: {
			onsubmit(){
				var that = this;
				if (that.form.account != '' && that.form.account != null  ) {
					if ( that.form.password != ''&& that.form.password != null ) {
						console.log(that.form)
						// user/login
						that.$post('user/login', that.form).then(res => {
							if (res.code != 0) {
								console.log(res, 11111)
								uni.showToast({
									title: '登录成功',
									icon: 'none'
								});
								uni.setStorageSync('data', res.data.userinfo);
								uni.setStorageSync('token', res.data.userinfo.token);
								// uni.setStorageSync('xianshi', res.data.userinfo.group_id);			
						
								// uni.getStorageSync('ceshi')  //获取缓存
						
						
								// uni.removeStorageSync(token)：///从本地缓存中同步移除指定key的数据。
						
								// uni.clearStorageSync()：//清空本地缓存中所有数据。
						
								setTimeout(() => {
						
									uni.reLaunch({
										url: '/pages/index/index',
									});
								}, 1000)
							} else {
								console.log(res)									
								uni.showToast({
									title: res.msg,
									icon: 'none',
									duration: 2000
								});
							}
						
						
						})
					}else{
						uni.showToast({
							title: '请输入密码',
							icon: 'none',
							duration: 2000
						});
					}
					
				}else{
					uni.showToast({
						title: '请输入手机号',
						icon: 'none',
						duration: 2000
					});
				}
			},
			
		}
	}
</script>

<style>
 .input-container {
    margin: 20px;
    padding: 10px;
	overflow: hidden;
	width: 90%;
	margin: 0 auto;
    /* background-color: #f2f2f2; */
 /*   border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); */
  }
 
  .input-field {
    width: 93%;
    padding: 10px;
    border: 1rpx solid red;
    border-radius: 50px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    font-size: 16px;
  }
 
  .input-field::-webkit-input-placeholder {
    color: #c0c0c0;
  }
 
  .input-field:focus {
    outline: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }
     .button{
          margin-top: 120rpx;
           
          button{
              background-color:#11c53e;
              width: 90%;
              height: 85rpx;
              text-align: center;
              line-height: 85rpx;
              color: #fff;
          }
      }
</style>
